require "Common/define"
require "Logic/Config"
require "Net/send_Msg"
require "proto/lottery/message/ReqDrawMessage"
require "proto/lottery/message/ReqOpenPoolMessage"
require "proto/lottery/message/ReqPoolMessage"
require "proto/lottery/message/ReqDrawCrystalMessage"
require "proto/lottery/message/ReqSelectDrawRefreshMessage"
require "proto/lottery/message/ReqSelectDrawSaveMessage"
require "proto/lottery/message/ReqSelectDrawBuyMessage"
require "proto/lottery/message/ReqSetAppointDrawHeroMessage"
require "proto/lottery/message/ReqAppointDrawInfoMessage"
require "proto/lottery/message/ReqAppointDrawMessage"
require "proto/wish/message/ReqSendWishInfoMessage"
require "proto/wish/message/ReqResetWishMessage"
require "proto/wish/message/ReqDrawRewardMessage"
require "proto/wish/message/ReqChooseBigRewardMessage"
require "proto/lottery/message/ReqDrawProcessInfoMessage"
require "proto/lottery/message/ReqSetVocationDrawHeroMessage"
require "proto/lottery/message/ReqVocationDrawInfoMessage"
require "proto/lottery/message/ReqVocationDrawMessage"
require "proto/lottery/message/ReqWishHeroMessage"
require "proto/lottery/message/ReqWishListMessage"
drawHandler = drawHandler or {};

drawHandler.WishSource = {}
drawHandler.RecordbigRewardID = 0;

drawHandler.dpRewards={}
drawHandler.IsAskProcess=false
drawHandler.drawProcessMsg=nil
drawHandler.drawNum=0

--- 许愿池下次免费重置时间
--- @type number
drawHandler.pondNextfreeResetTime = nil
--- 许愿池免费次数
--- @type number
drawHandler.pondFreeCount = 0

--- 钻石抽奖下次免费重置时间
--- @type number
drawHandler.diamondNextfreeResetTime = nil
--- 钻石抽奖免费次数
--- @type number
drawHandler.diamondFreeCount = 0

function drawHandler.receivePacket(msg)
    if msg.state == 0 then --- 不知道为啥刷新在处理数据之前,所以单独写一个
        logicMgr.HeroManager.setDrawTodayCount(msg.poolId, msg.todyDrawCount)
    end
    FireEvent(Config.EventType.Fresh_Draw)
    if msg.state == 0 then
        --抽卡成功
        local _drawDic = {}
        _drawDic.times = tonumber(msg.drawTimes)
        _drawDic.pool_id = tostring(msg.poolId)
        local _drawItemsList = {}
        local _itemPropertyList = {}
        local _heroCfg = G.dataTable["t_hero"]
        for key, item in pairs(msg.items) do
            _itemPropertyList = {}
            _itemPropertyList.hero_id = tostring(item.itemModelId)
            _itemPropertyList.hero_name = getLanguage(_heroCfg[_itemPropertyList.hero_id].f_HeroName)
            -- if string.IsNilOrEmpty(_itemPropertyList.item_name) and _heroCfg[_itemPropertyList.item_id] then
            --     _itemPropertyList.item_name = getLanguage(_heroCfg[_itemPropertyList.item_id].f_HeroName)
            -- end
            _itemPropertyList.num = tostring(item.num)
            
            table.insert(_drawItemsList,_itemPropertyList)
        end
        drawHandler.Track_DrawSuccess(getJsonStr(_drawItemsList))
        
        -- _drawDic.draw_process = 
        local list = msg.items
        if UIDraw then
            UIDraw.receiveDrawMsg(list);
        end
    else
        if msg.state == 1222 then
            closeUI(PanelNames.UIDrawResult)
        end
        if UIDraw then
            UIDraw.receiveDrawMsgError();
        end
    end
end

function drawHandler.sendDrawMessage(poolId, times,isExtra)
    local msg = ReqDrawMessage.New();
    msg.poolId = poolId;
    msg.drawTimes = times;
    msg.isExtraBestHero = isExtra
    sendReqMessage(msg);
end

function drawHandler.receiveResPool(msg)
    if msg.state == 0 then
        UIDraw.receivePoolMsg(msg);
        for k , v in pairs(msg.pools) do
            logicMgr.HeroManager.setDrawTodayCount(v.poolId, v.todyDrawCount)
        end
        FireEvent(Config.EventType.Fresh_Draw)
    end
end

function drawHandler.sendReqPoolMessage(poolIdList)
    local msg = ReqPoolMessage.New();
    msg.poolIds = {};
    for _,v in pairs(poolIdList) do
        table.insert(msg.poolIds, tonumber(v))
    end
    sendReqMessage(msg);
end

function drawHandler.receiveResOpenPool(msg)
    if msg.state == 0 then
        UIDrawProbability.receiveOpenPoolMsg(msg);
    end
end

function drawHandler.sendReqOpenPoolMessage(poolId)
    local msg = ReqOpenPoolMessage.New();
    msg.poolId = poolId;
    sendReqMessage(msg);
end

--水晶信息返回
function drawHandler.receiveCrystalInfo(msg)
    --log("drawHandler.receiveCrystalInfo");
    --dataTable.PrintTable(msg);
    if msg.state == 0 then
        logicMgr.HeroManager.setCrystalInfo(msg);
        FireEvent(Config.EventType.Fresh_Crystal);
    end
end

--水晶奖励返回
function drawHandler.receiveCrystalReward(msg)
    --log("drawHandler.receiveCrystalReward");
    --dataTable.PrintTable(msg);
    if msg.state == 0 then
        local config = G.dataTable["t_crystal"];
        local level = logicMgr.HeroManager.getCrystalInfo().level;
        local exp = logicMgr.HeroManager.getCrystalInfo().exp;
        local cfg = config[tostring(level)]
        if cfg ~= nil then
            local rewards = decodeJsonStrToTabel(cfg.f_Reward);
            local rewards1 = {}
            for k, v in pairs(rewards) do
                local itemCg = G.dataTable["t_item"][tostring(v[1])];
                if itemCg ~= nil then
                    local data = {};
                    data["icon"] = itemCg.f_Icon;
                    data["num"] = v[2];
                    data["quality"] = itemCg.f_Quality;
                    table.insert(rewards1, data)
                else
                    logError("找不到 item config , id:" .. v[1])
                end
            end
            showUI(PanelNames.UICommonItemGet, nil, nil, 3, rewards1)
            exp = exp - cfg.f_Value;
            level = level + 1;
        end
        local data = { crystalLevel = level, crystalValue = exp };
        logicMgr.HeroManager.setCrystalInfo(data);
        FireEvent(Config.EventType.Fresh_Crystal);
    end
end

--连斩召唤刷新返回
function drawHandler.receiveSelectDrawRefresh(msg)
    if msg.state == 0 then
        logicMgr.ActiveManager.resSelectDrawRefresh(msg);
    end
end

--连斩召唤纪录返回
function drawHandler.receiveSelectDrawSave(msg)
    if msg.state == 0 then
        FireEvent(Config.EventType.Fresh_SelectDrawSave);
    end
end

--连斩召唤购买返回
function drawHandler.receiveSelectDrawBuy(msg)
    if msg.state == 0 then
        FireEvent(Config.EventType.Fresh_SelectDrawBuy);
        logicMgr.ActiveManager.resSelectDrawBuy(msg);
    end
end

--设置定向抽卡的英雄返回
 function drawHandler.receiveSetAppointDrawHero(msg)
    if msg.state == 0 then
        UISysTips.AddMsg(getLanguage("Sys_MsgTargetDraw_Set"));
        FireEvent(Config.EventType.Fresh_SelectHero,msg.selectHeroID); 
    end
 end

 --定向卡池信息请求返回
function drawHandler.receiveAppointDrawInfo(msg)
    if msg.state==0 then
        FireEvent(Config.EventType.Fresh_AppointDrawInfo,msg);
    end

end
 --定向卡池信息请求返回
 function drawHandler.receiveAppointDraw(msg)
    FireEvent(Config.EventType.Fresh_Draw)
    if msg.state==0 then
        --抽卡成功
        local _drawDic = {}
        _drawDic.times = tonumber(msg.drawTimes)
        _drawDic.pool_id = tostring(msg.poolId)
        local _drawItemsList = {}
        local _itemPropertyList = {}
        local _heroCfg = G.dataTable["t_hero"]
        for key, item in pairs(msg.items) do
            _itemPropertyList = {}
            _itemPropertyList.item_id = tostring(item.itemModelId)
            _itemPropertyList.item_name = ItemManager.GetItemName(_itemPropertyList.item_id)
            if string.IsNilOrEmpty(_itemPropertyList.item_name) and _heroCfg[_itemPropertyList.item_id] then
                _itemPropertyList.item_name = getLanguage(_heroCfg[_itemPropertyList.item_id].f_HeroName)
            end
            _itemPropertyList.num = tostring(item.num)
            
            table.insert(_drawItemsList,_itemPropertyList)
        end
       
        drawHandler.Track_DrawSuccess(getJsonStr(_drawItemsList))
        
        local list = msg.items
        UIDraw.receiveDrawMsg(list);
    else
        UIDraw.receiveDrawMsgError();
    end

end
--返回抽卡进度
function drawHandler.receiveDrawProcessInfo(msg)
    if(msg.state==0)then
        drawHandler.drawProcessMsg=msg
        if drawHandler.IsAskProcess then
            drawHandler.IsAskProcess=false
            FireEvent(Config.EventType.Fresh_DrawProcess,msg)
            drawHandler.ClearDpReward()
        else
            drawHandler.SetDrawProcessInfo(msg)
        end
        if msg.haveReward~=0 then
            FireEvent(Config.EventType.Fresh_Drenum)
        end
    end
end
function drawHandler.SetDrawProcessInfo(msg)
    local data={}
    data.itemModelId=msg.itemID
    data.num=msg.itemCount

    --drawHandler.isShowDPReward=true
    drawHandler.drawNum=msg.totalDrawCount
    if drawHandler.dpRewards==nil then
        drawHandler.dpRewards={}
    end
    local index=-1
    if data.itemModelId~=0 then
        for i,v in ipairs(drawHandler.dpRewards)do
            if v.itemModelId==data.itemModelId then
                index=i
                break
            end
        end
        if index>0 then
            drawHandler.dpRewards[index].num=drawHandler.dpRewards[index].num+data.num
        else
            table.insert(drawHandler.dpRewards,data)
        end
    end
end
function drawHandler.ClearDpReward()
    drawHandler.isShowDPReward=false
    drawHandler.dpRewards={}
end
--请求抽卡进度
function drawHandler.SendDrawProcessInfo()
    local req = ReqDrawProcessInfoMessage.New()
    sendReqMessage(req)
end
--设置定向抽卡的英雄
function drawHandler.SendSetAppointDrawHero(selectHeroID)
    if selectHeroID~=nil then
        local req = ReqSetAppointDrawHeroMessage.New();
        req.selectHeroID=tonumber(selectHeroID);
        sendReqMessage(req);
    end
 end

 --定向卡池信息请求
function drawHandler.SendAppointDrawInfo()
    local req = ReqAppointDrawInfoMessage.New();
    sendReqMessage(req);

end

 --定向卡池信息请求
 function drawHandler.SendAppointDraw(poolId,drawTimes)
    local req = ReqAppointDrawMessage.New();
    req.poolId=tonumber(poolId);
    req.drawTimes=drawTimes;
    sendReqMessage(req);

end

 --设置职业抽卡的英雄返回
 function drawHandler.receiveSetVocationDrawHero(msg)
    if msg.state==0 then
       if msg.result==0 then
            if msg.selectHeroVocationID1==0 or msg.selectHeroVocationID2==0 then
                   return ; 
            end
            FireEvent(Config.EventType.Fresh_OccDraw,msg.selectHeroVocationID1,msg.selectHeroVocationID2);
       end
    end
    
end

--职业抽卡请求返回
function drawHandler.receiveVocationDraw(msg)
    FireEvent(Config.EventType.Fresh_Draw)
    if msg.state==0 then
        --抽卡成功
        local _drawDic = {}
        _drawDic.times = tonumber(msg.drawTimes)
        _drawDic.pool_id = tostring(msg.poolId)
        local _drawItemsList = {}
        local _itemPropertyList = {}
        local _heroCfg = G.dataTable["t_hero"]
        for key, item in pairs(msg.items) do
            _itemPropertyList = {}
            _itemPropertyList.item_id = tostring(item.itemModelId)
            _itemPropertyList.item_name = ItemManager.GetItemName(_itemPropertyList.item_id)
            if string.IsNilOrEmpty(_itemPropertyList.item_name) and _heroCfg[_itemPropertyList.item_id] then
                _itemPropertyList.item_name = getLanguage(_heroCfg[_itemPropertyList.item_id].f_HeroName)
            end
            _itemPropertyList.num = tostring(item.num)
            
            table.insert(_drawItemsList,_itemPropertyList)
        end
        drawHandler.Track_DrawSuccess(getJsonStr(_drawItemsList))
        
        
        local list = msg.items
        UIDraw.receiveDrawMsg(list);
    else
        UIDraw.receiveDrawMsgError();
    end
end

--职业卡池信息请求返回
function drawHandler.receiveVocationDrawInfo(msg)
    if msg.state==0 then
        FireEvent(Config.EventType.Fresh_OccDraw,msg.selectHeroVocationID1,msg.selectHeroVocationID2);
    end
end

 --设置职业抽卡的英雄
 function drawHandler.SendSetVocationDrawHero(selectHeroVocationID1,selectHeroVocationID2)
    local req = ReqSetVocationDrawHeroMessage.New();
    req.selectHeroVocationID1=tonumber(selectHeroVocationID1);
    req.selectHeroVocationID2=tonumber(selectHeroVocationID2);
    sendReqMessage(req);
end

--职业卡池信息请求
function drawHandler.SendVocationDrawInfo()
    local req = ReqVocationDrawInfoMessage.New();
    sendReqMessage(req);
    
end

--职业抽卡请求
function drawHandler.SendVocationDraw(drawTimes)
local req = ReqVocationDrawMessage.New();
    req.drawTimes=drawTimes;
    sendReqMessage(req);
end


--水晶奖励领取
function drawHandler.sendCrystal()
    local req = ReqDrawCrystalMessage.New();
    sendReqMessage(req);
end

function drawHandler.GoReqSendWishInfoMessage()
    local req = ReqSendWishInfoMessage.New();
    sendReqMessage(req);
end

--- @param msg ResSendWishInfoMessage
function drawHandler.ReceiveSendWishInfoMessage(msg)
    if msg.state == 0 then
        drawHandler.WishSource = msg;
        -- 下次免费抽奖重置时间
        print('ReceiveSendWishInfoMessage: ', tonumber(tostring(msg.nextfreeDrawResetTime)), msg.freeDrawCount)
        if msg.nextfreeDrawResetTime ~= nil then
            if drawHandler.pondNextfreeResetTime == nil then
                drawHandler.pondNextfreeResetTime = tonumber(tostring(msg.nextfreeDrawResetTime))
                FireEvent(Config.EventType.Fresh_Free_Pond)
            else
                drawHandler.pondNextfreeResetTime = tonumber(tostring(msg.nextfreeDrawResetTime))
            end
        end
        if msg.freeDrawCount ~= nil then
            drawHandler.pondFreeCount = tonumber(msg.freeDrawCount)
        end
        logicMgr.HeroManager.setDrawTodayCount(EnumConst.drawType.Pond, msg.todayDrawCount)
        FireEvent(Config.EventType.WishPondSourceChange);
    end
end

function drawHandler.GoReqChooseBigRewardMessage(CardID)
    local req = ReqChooseBigRewardMessage.New();
    req.bigRewardID = CardID
    drawHandler.RecordbigRewardID = CardID
    sendReqMessage(req);
end

function drawHandler.ReceiveResChooseBigRewardMessage(msg)
    if msg.state == 0 then
        drawHandler.WishSource.bigRewardID = drawHandler.RecordbigRewardID;
        drawHandler.WishSource.drawBigReward = 0;
        TAManager.TrackByDictionary("wishfountain_reset", {hero_id = tostring(drawHandler.RecordbigRewardID)});
        FireEvent(Config.EventType.WishSetBigReward);
        FireEvent(Config.EventType.WishPondSourceChange);
    end
end

function drawHandler.GoReqDrawRewardMessage(DrawTime)
    local req = ReqDrawRewardMessage.New();
    req.drawCount = DrawTime
    sendReqMessage(req);
end

function drawHandler.ReceiveResDrawRewardMessage(msg)
    if msg.state == 0 then
        logicMgr.HeroManager.setDrawTodayCount(EnumConst.drawType.Pond, msg.todayDrawCount)
        local list = {}
        for i = 1, #msg.items do
            if (msg.items[i].type == 2) then
                local singledata = {}
                singledata["itemModelId"] = msg.items[i].itemInfos[1].itemID;
                table.insert(list, singledata)
            end
        end
        FireEvent(Config.EventType.WishGetReward, msg);
    end
end

function drawHandler.GoReqResetWishMessage()
    local req = ReqResetWishMessage.New();
    sendReqMessage(req);
end

function drawHandler.GoReqSelectDrawRefreshMessage(id)
    local req = ReqSelectDrawRefreshMessage.New();
    req.activityId = id;
    sendReqMessage(req);
end

function drawHandler.GoReqSelectDrawSaveMessage(id, boxId)
    local req = ReqSelectDrawSaveMessage.New();
    req.activityId = id;
    req.boxId = boxId;
    sendReqMessage(req);
end

function drawHandler.GoReqSelectDrawBuyMessage(id, boxId)
    local req = ReqSelectDrawBuyMessage.New();
    req.activityId = id;
    req.boxId = boxId;
    sendReqMessage(req);
end
--召唤心愿
function drawHandler.ReqWishHeroData(heros,extraIds)
    local req = ReqWishHeroMessage.New()
    req.wishHeroDataList = {}
    req.bestHeroIds = {}
    local wishHeroData
    for k,map in pairs(heros) do
        if k < 7 then
            wishHeroData = WishHeroData.New()
            wishHeroData.wishHeroId = {}
            for _,vv in pairs(map) do
                if vv ~= 0 then
                    table.insert(wishHeroData.wishHeroId, vv)
                end
            end
            table.insert(req.wishHeroDataList, wishHeroData)
        else
            if k==7 then
                for _,v in pairs(heros[7]) do
                    if v~=0 then
                        table.insert(req.bestHeroIds,v)
                    end
                end
            end
        end
    end
    req.extraBestHeroId = 0
    req.extraBestHeroIds = {}
    for _,v in pairs( extraIds) do
        if v~=0 then
            table.insert(req.extraBestHeroIds,v)
        end
    end
    sendReqMessage(req)
end
function drawHandler.ResWishHeroData(msg)
    logicMgr.HeroManager.SetWishData(msg)
    -- 下次免费抽奖重置时间
    print('ResWishHeroData: ', tonumber(tostring(msg.nextfreeDrawResetTime)), msg.freeDrawCount)
    if msg.nextfreeDrawResetTime ~= nil then
        if drawHandler.diamondNextfreeResetTime == nil then
            drawHandler.diamondNextfreeResetTime = tonumber(tostring(msg.nextfreeDrawResetTime))
            FireEvent(Config.EventType.Fresh_Free_Summon)
        else
            drawHandler.diamondNextfreeResetTime = tonumber(tostring(msg.nextfreeDrawResetTime))
        end
    end
    if msg.freeDrawCount ~= nil then
        drawHandler.diamondFreeCount = tonumber(msg.freeDrawCount)
    end
    FireEvent(Config.EventType.UpdateWishHeroData)
end
function drawHandler.ReqHeroInfo()
    local req = ReqWishListMessage.New()
    sendReqMessage(req)
end

function drawHandler.Track_DrawSuccess(lsstr)
    local dic = {}
    dic.resultList = lsstr
    -- 
    dic.draw_process = logicMgr.HeroManager.total_draw_count

    local list = logicMgr.HeroManager.GetWishData()
    local index = 1
    for k,v in pairs(list) do
        for kk,vv in pairs(v) do
            dic["wish_" .. index] = vv
            index = index + 1
        end
    end
    dic.extra_num = logicMgr.HeroManager.extraNum
    if logicMgr.HeroManager.extraNum > 0 then
        local ext = HeroManager.GetExtraHero()
        if ext then
            dic["wish_13"] = ext[1]
            dic["wish_14"] = ext[2]
        end
    end
    
    TAManager.TrackByDictionary("draw_cards_success", dic)
end
--- 抽卡后更新重复英雄计数
--function drawHandler.UpdateHeroInfoForSeamNum(list)
--    if list then
--        for _, v in pairs(list) do
--            local elementModelId = v["itemModelId"]
--            local cfgInfo = dataTable.getRow("t_hero", elementModelId)
--            if cfgInfo then
--                local heroInfo = logicMgr.HeroManager.getHeroDatabyModelId(elementModelId)
--
--                if heroInfo then
--                    local heroData = logicMgr.HeroManager.getHeroDatabyPartnerId(heroInfo["partnerId"]);
--                    local sameNum = cfgInfo["f_RepeatCount"] * (v["num"] or 1)
--                    if heroData ~= nil then
--                        if heroData and heroData.isNew then
--                            sameNum = 0;
--                            logicMgr.HeroManager.setHeroIsNew(heroInfo["partnerId"],false);
--                        end
--                        logicMgr.HeroManager.setHeroSameNum(heroInfo["partnerId"], sameNum, true)
--                    end
--                end
--            end
--        end
--    end
--end

--- 常规卡池免费召唤剩余时间
--- @return number 剩余时间
function drawHandler.getNormalSummonFreeLeftTime()
    -- 没有数据时发起请求
    if drawHandler.diamondNextfreeResetTime == nil then
        drawHandler.ReqHeroInfo()
        return 10
    end

    local nextTick = Mathf.Floor(drawHandler.diamondNextfreeResetTime / 1000)
    local currTime = HelperFunc.GetServerTime()
    return Mathf.Max(0, Mathf.Floor(nextTick - currTime))
end

--- 许愿水晶免费召唤剩余时间
--- @return number 剩余时间
function drawHandler.getDrawPondFreeLeftTime()
    -- 没有数据时发起请求
    if drawHandler.pondNextfreeResetTime == nil then
        drawHandler.GoReqSendWishInfoMessage()
        return 10
    end

    local nextTick = Mathf.Floor(drawHandler.pondNextfreeResetTime / 1000)
    local currTime = HelperFunc.GetServerTime()
    return Mathf.Max(0, Mathf.Floor(nextTick - currTime))
end


-----------------------------------------------------
--  限时抽卡
-----------------------------------------------------
require "proto/timelimit/lottery/message/ReqTimelimitLotteryInfoMessage"
require "proto/timelimit/lottery/message/ReqChooseUPHeroMessage"
require "proto/timelimit/lottery/message/ReqLotteryMessage"

drawHandler.ActivityDrawSource = {}

-- 请求限时抽卡
function drawHandler.reqTimeLimitDraw( _activity_id, _times )
    -- print("召唤--->",  _activity_id, _times )
    if _times + logicMgr.HeroManager.getDrawTodayCount(_activity_id) > dataTable.getGlobalInt(616) then
        UISysTips.AddMsg(getLanguage("Draw_TimeLimitReached"));
        return ;
    end
    local req = ReqLotteryMessage.New()
    req.activityId = _activity_id
    req.times = _times
    sendReqMessage(req)
end

-- 请求选择UP英雄
function drawHandler.reqChooseUpHero( _activity_id, _hero_id )
    -- print("请求选择UP英雄reqChooseUpHero",  _activity_id, _hero_id)
    local req = ReqChooseUPHeroMessage.New()
    req.activityId = _activity_id
    req.upHero = _hero_id
    sendReqMessage(req)
end

-- 请求抽卡信息
function drawHandler.reqTimeLimitDrawInfo( _activity_id )
    -- print("请求抽卡信息", _activity_id)
    local req = ReqTimelimitLotteryInfoMessage.New()
    req.activityId = _activity_id -- 活动id
    sendReqMessage(req)
end

-- 返回抽卡信息
function drawHandler.resTimelimitLotteryInfo( msg )
    -- print("返回抽卡信息", table.tostring(msg) )
    drawHandler.ActivityDrawSource = {}
    if msg and msg.LotteryInfo ~= nil then
        drawHandler.ActivityDrawSource.activity_id = msg.activityId
        drawHandler.ActivityDrawSource.choose_hero_id = msg.LotteryInfo.upHero -- 英雄ID(0:未选定)
        drawHandler.ActivityDrawSource.remain_times = msg.LotteryInfo.remainTimes -- 保底次数(剩余必得)
        logicMgr.HeroManager.setDrawTodayCount(msg.activityId, msg.LotteryInfo.todayDrawCount)
    end
    if isOpenUI(PanelNames.UIActivityDraw) then
        local ui_activity_draw = CtrlManager.GetCtrl(PanelNames.UIActivityDraw) 
        ui_activity_draw:RefreshData()
    end
end

--返回抽卡
function drawHandler.resTimeLimitLottery( msg )
    -- print("返回抽卡", table.tostring(msg) )
    if msg and msg.state == 0 then
        drawHandler.ActivityDrawSource.choose_hero_id =  msg.LotteryInfo and msg.LotteryInfo.upHero or 0
        drawHandler.ActivityDrawSource.remain_times = msg.LotteryInfo and msg.LotteryInfo.remainTimes or 0-- 保底次数(剩余必得)
        logicMgr.HeroManager.setDrawTodayCount(msg.activityId, msg.LotteryInfo.todayDrawCount)
        if isOpenUI(PanelNames.UIActivityDraw) then
            local ui_activity_draw = CtrlManager.GetCtrl(PanelNames.UIActivityDraw)
            ui_activity_draw:RefreshData()
            ui_activity_draw:ShowDrawItem(msg.items)
        end
    end
end

-- 返回选择UP英雄
function drawHandler.resChooseUpHero( msg )
    -- print("返回选择UP英雄", table.tostring(msg) )
    if msg and msg.state == 0 then
        drawHandler.ActivityDrawSource = drawHandler.ActivityDrawSource or {}
        drawHandler.ActivityDrawSource.choose_hero_id = msg.upHero
        drawHandler.ActivityDrawSource.activity_id = msg.activityId
        drawHandler.ActivityDrawSource.remain_times = msg.LotteryInfo and msg.LotteryInfo.remainTimes or 0-- 保底次数(剩余必得)
        FireEvent(Config.EventType.LimitDrawActivity)
    end
end
-----------------------------------------------------
-- end
-----------------------------------------------------